package com.zxw.mallafter.api;

import com.zxw.mallafter.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping(value = "/api/v1/uploads", produces = "application/json;charset=UTF-8")
public class UploadFileApi {
    private UploadFileService uploadFileService;
    @Autowired
    public UploadFileApi(UploadFileService uploadFileService) {
        this.uploadFileService = uploadFileService;
    }
    @PostMapping("/avatar")
    public Map<String, Object> uploadAvatar(@RequestParam("file") MultipartFile file) {
        String url = uploadFileService.uploadAvatar(file);

        return Map.of("success", true, "url", url);
    }
}
